#include <linux/sched.h>
#include <linux/sched/task.h>
#include <linux/string.h>
#include <linux/init.h>

pid_t kernel_thread(int (*fn)(void *), void *arg, const char *name, unsigned long flags)
{
    struct kernel_clone_args args = {
        .flags = (u32)((flags | CLONE_VM | CLONE_UNTRACED) & ~CSIGNAL),
        .exit_signal = (flags & CSIGNAL),
        .fn = fn,
        .fn_arg = arg,
        .name = name,
        .kthread = 1,
    };

    return kernel_clone(&args);
}

/*
 * Create a user mode thread.
 */
pid_t user_mode_thread(int (*fn)(void *), void *arg, unsigned long flags)
{
    struct kernel_clone_args args = {
        .flags = (u32)((flags | CLONE_VM | CLONE_UNTRACED) & ~CSIGNAL),
        .exit_signal = (flags & CSIGNAL),
        .fn = fn,
        .fn_arg = arg,
        .name = "_user_",
    };

    return kernel_clone(&args);
}
